from django.contrib.auth.models import Permission, ContentType, Group
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from meiduo_admin.serialziers.group import GroupSerializer
from meiduo_admin.serialziers.permission import PermissionSerializer
from meiduo_admin.utils.page import PageNum


class GroupView(ModelViewSet):
    permission_classes = [IsAdminUser, ]
    serializer_class = GroupSerializer
    queryset = Group.objects.all()
    pagination_class = PageNum

    def simple(self, request):
        """
        获取权限数据
        :param request:
        :return:
        """
        # 查询权限表
        data = Permission.objects.all()

        # 返回权限数据
        ser = PermissionSerializer(data, many=True)
        return Response(ser.data)
